from rest_framework.response import Response
from rest_framework.views import APIView
from rest_framework.viewsets import ModelViewSet

from apps.meiduo_admin.serializers.orders import OrderModelSerializer
from apps.meiduo_admin.utils import PageNum
from apps.orders.models import OrderInfo


class OrdersAPIView(ModelViewSet):
    queryset = OrderInfo.objects.all()
    serializer_class = OrderModelSerializer
    pagination_class = PageNum

class OrderStatusAPIView(APIView):
    def put(self, request, pk):
        order = OrderInfo.objects.get(order_id=pk)
        status = request.data.get('status')
        order.status = status
        order.save()
        serializer = OrderModelSerializer(order)
        return Response({
            'order_id': order.order_id,
            'status': status
        })